<!--
  #%L
  thinkbig-ui-feed-manager
  %%
  Copyright (C) 2017 ThinkBig Analytics
  %%
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at
  
      http://www.apache.org/licenses/LICENSE-2.0
  
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  #L%
  -->
<div>
    <md-progress-linear md-mode="indeterminate" ng-if="vm.loading"></md-progress-linear>
    <card-layout body-css="md-padding" class="centered" ng-if="!vm.loading">
        <header-section>
            <div layout="row" layout-align="center start">
                <div class="card-title">组详情</div>
                <span flex></span>
                <ng-md-icon icon="group" style="padding-right: 16px" size="30"></ng-md-icon>
            </div>
        </header-section>
        <body-section>
            <form name="groupForm">
                <vertical-section-layout section-title="详情" on-delete="vm.onDelete()" allow-delete="vm.canDelete()" on-save-edit="vm.onSave()" on-edit="vm.onEdit()" on-cancel-edit="vm.onCancel()"
                                         editable="vm.isEditable" is-valid="vm.isValid" allow-edit="vm.allowAdmin">
                    <readonly-section>
                        <div layout="row" class="layout-padding-top-bottom">
                            <span flex="25" class="property-name">组名称</span>

                            <div flex>
                                {{vm.model.systemName}}
                            </div>
                        </div>
                        <div layout="row" class="layout-padding-top-bottom">
                            <span flex="25" class="property-name">标题</span>

                            <div flex>
                                {{vm.model.title}}
                            </div>
                        </div>
                        <div layout="row" class="layout-padding-top-bottom">
                            <span flex="25" class="property-name">描述</span>

                            <div flex>
                                {{vm.model.description}}
                            </div>
                        </div>
                    </readonly-section>
                    <editable-section>
                        <md-input-container class="md-block" ng-if="vm.model.systemName === null">
                            <label>组 名称</label>
                            <input name="systemName" type="text" ng-model="vm.editModel.systemName"/>
                            <div ng-messages="vm.$error" md-auto-hide="false">
                                <div ng-message="duplicateName">该组名已被使用。.</div>
                                <div ng-message="missingName">需要组名称.</div>
                            </div>
                        </md-input-container>
                        <div layout="row" class="layout-padding-top-bottom" ng-if="vm.model.systemName !== null">
                            <span flex="25" class="property-name">组名</span>

                            <div flex>
                                {{vm.editModel.systemName}}
                            </div>
                        </div>

                        <md-input-container class="md-block">
                            <label>标题</label>
                            <input ng-model="vm.editModel.title"/>
                        </md-input-container>

                        <md-input-container class="md-block">
                            <label>描述</label>
                            <input ng-model="vm.editModel.description"/>
                        </md-input-container>
                    </editable-section>
                </vertical-section-layout>
            </form>
            <vertical-section-layout section-title="权限" on-save-edit="vm.onSavePermissions()" on-edit="vm.onEditPermissions()" editable="vm.isPermissionsEditable"
                                     allow-edit="!vm.loading && vm.model.systemName !== null && vm.allowAdmin" ng-if="vm.groupId">
                <readonly-section>
                    <thinkbig-permissions-table allowed="vm.actions" read-only="true"></thinkbig-permissions-table>
                </readonly-section>
                <editable-section>
                    <thinkbig-permissions-table allowed="vm.editActions"></thinkbig-permissions-table>
                </editable-section>
            </vertical-section-layout>
            <vertical-section-layout allow-edit="false" show-vertical-check="true" section-title="相关用户" ng-if="vm.allowUsers" ng-if="vm.groupId">
                <readonly-section>
                    <md-list layout-fill class="list-item-table list-condensed" id="policy-list" ng-if="!vm.loading && vm.model.systemName !== null && vm.model.memberCount > 0">
                        <md-list-item>
                            <div layout="row" layout-fill>
                                <div flex="30" class="md-list-item-text hint">
                                    显示名称
                                </div>
                                <div flex="50" class="md-list-item-text hint">
                                    Email 地址
                                </div>
                                <div flex="20" class="md-list-item-text hint">
                                    活跃
                                </div>
                            </div>
                        </md-list-item>
                        <md-list-item ng-repeat="user in vm.users" ng-click="vm.onUserClick(user)">
                            <div layout="row" layout-fill>
                                <div flex="30" class="md-list-item-text">
                                    <md-input-container class="md-block" flex-gt-sm>
                                        <div>{{vm.getUserName(user)}}</div>
                                    </md-input-container>
                                </div>
                                <div flex="50" class="md-list-item-text">
                                    {{user.email}}
                                </div>
                                <div flex="20" class="md-list-item-text">
                                    <ng-md-icon icon="check" ng-if="user.enabled"></ng-md-icon>
                                </div>
                            </div>
                        </md-list-item>
                    </md-list>
                    <div ng-if="vm.loading || vm.model.systemName === null || vm.model.memberCount === 0">
                        没有与此组关联的用户。
                    </div>
                </readonly-section>
            </vertical-section-layout>
        </body-section>
    </card-layout>
</div>
